﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kaiser.UnityInstaller
{
    public class UnityInstaller
    {
        private static bool _hasInit;

        public static void Install()
        {
            _hasInit = true;
            //facade 
            IocContainer.Current.RegisterType<IContactFacade, ContactFacade>();
            IocContainer.Current.RegisterType<IMediaFacade, MediaFacade>();
            IocContainer.Current.RegisterType<IGlossaryFacade, GlossaryFacade>();
            IocContainer.Current.RegisterType<IRegionalEconomicFacade, RegionalEconomicFacade>();

            //domainservice
            IocContainer.Current.RegisterType(typeof(MediaService));
            IocContainer.Current.RegisterType(typeof(ContactService));
            IocContainer.Current.RegisterType(typeof(RegionalEconomicService));


            //repository
            IocContainer.Current.RegisterType<IBaseDomainService, BaseDomainService>();
            IocContainer.Current.RegisterType<IGlossaryRepository, GlossaryRepository>();

            IocContainer.Current.RegisterType<IContactInfoRepository, ContactInfoRepository>();
            IocContainer.Current.RegisterType<IEnterpriseInfoRepository, EnterpriseInfoRepository>();
            IocContainer.Current.RegisterType<IContactEnterpriseWorkInReporstory, ContactEnterpriseWorkInReporstory>();

            IocContainer.Current.RegisterType<IMediaNewsRepository, MediaNewsRepository>();
            IocContainer.Current.RegisterType<IMediaRegulationRepository, MediaRegulationRepository>();
            IocContainer.Current.RegisterType<IMediaReportRepository, MediaReportRepository>();

            IocContainer.Current.RegisterType<INationRatioMarketRepsitory, NationRatioMarketRepsitory>();
            IocContainer.Current.RegisterType<INationRatioBankRepsitory, NationRatioBankRepsitory>();


            //unitofwork
            IocContainer.Current.RegisterType<IQueryableUnitOfWork, BondStockUnitOfWork>(new PerResolveLifetimeManager());
        }

        public static T Resolve<T>()
        {
            if (_hasInit == false)
                Install();
            return IocContainer.Current.Resolve<T>();
        }
    }
}
